package com.mrs.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * description: Result
 * date: 2022/7/15 19:37
 * author: MR.孙
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {

    private Integer code;
    private String msg;
    private T data;

    public Result(String msg, T data) {
        this.msg=msg;
        this.data=data;
    }


    public static <T> Result<T> success(String msg,T data){
       return new Result<T>(HttpEnum.Code.OK.code, msg,data);
   }

    public static <T> Result<T> success(T data){
        return new Result<T>(HttpEnum.Code.OK.code,"操作成功",data);
    }

    public static <T> Result<T> fail(String msg){
        return new Result<T>(msg,null);
    }

    public static <T> Result<T> fail(HttpEnum.Code code,String msg){
        return new Result<T>(code.code,msg,null);
    }

}
